/**
 * 事件发布，监听
 */
define(["jquery"], function($){
	var handlers = {};
	return {
		publish : function (topic, data) {
	        var subs = handlers[topic] || [];
	        for (var i = 0; subs[i]; i++) {
	        	try{subs[i].apply(this, data || [])}catch(e){if(console){console.debug(e)}};
	        };
	    },
	    subscribe : function (topic, handler) {
	        (handlers[topic] = handlers[topic] || []).push(handler);
	        return {
	        	remove : function(){
	        		$.each(handlers[topic],function(i,h){
	        			if(h==handler){
	        				handlers[topic].splice(i,1);
						}
	        		});
	        	}
	        };
	    }
	}
});